<template>
  <div class="container">
    <!-- 1.0 卡片的布局 -->
    <Card :arr="list" />

    <!-- 2.0 图表的展示 -->
    <MyChart :info="datas" />
  </div>
</template>

<script>
import Card from './components/Card.vue'
import MyChart from './components/MyChart.vue'
import { getDashData } from '@/api/charts.js'

export default {
  components: {
    Card,
    MyChart
  },
  data() {
    return {
      list: [
        {
          id: 1,
          title: '总订单',
          count: '',
          icon: 'icon-wenjian',
          color: '#1296db',
          name: 'totalOrder'
        },
        {
          id: 2,
          title: '总销售额',
          count: '',
          icon: 'icon-Dollar',
          color: '#d4237a',
          name: 'totalAmount'
        },
        {
          id: 3,
          title: '今日订单',
          count: '',
          icon: 'icon-icon-',
          color: '#1296db',
          name: 'todayOrder'
        },
        {
          id: 4,
          title: '今日销售额',
          count: '',
          icon: 'icon-renminbi',
          color: '#1afa29',
          name: 'totayAmount'
        }
      ],
      datas: {}
    }
  },
  mounted() {
    this.getDatas()
  },
  methods: {
    async getDatas() {
      const data = await getDashData()
      this.datas = data
      // 给首页的卡片设置数据
      this.list.forEach(item => {
        item.count = data[item.name]
      })
    }
  }
}
</script>

<style lang="less" scoped></style>
